package com.linkallcloud.log.web.domain;

import com.linkallcloud.core.enums.LoginMode;
import com.linkallcloud.core.www.ISimpleUser;
import com.linkallcloud.log.core.domain.BusiLog;
import com.linkallcloud.web.session.SessionBUser;
import com.linkallcloud.web.session.SessionCUser;

public class BusiWebLog extends BusiLog {
    private static final long serialVersionUID = -4483869993015515550L;

    /**
     * 操作者信息
     ***********************/
    private Long orgId;// 操作者所属的组织ID
    private String orgType;// 操作者所属的组织类型
    private Long operatorId;// 操作者的id
    private String operatorAccount;// 操作者的登录名
    private String operatorName;// 操作者的姓名

    /**
     * 操作终端信息
     ***********************/

    private String url;// url
    private String ua;// navigator.userAgent

    public Long getOrgId() {
        return orgId;
    }

    public void setOrgId(Long orgId) {
        this.orgId = orgId;
    }

    public String getOrgType() {
        return orgType;
    }

    public void setOrgType(String orgType) {
        this.orgType = orgType;
    }

    public Long getOperatorId() {
        return operatorId;
    }

    public void setOperatorId(Long operatorId) {
        this.operatorId = operatorId;
    }

    public String getOperatorAccount() {
        return operatorAccount;
    }

    public void setOperatorAccount(String operatorAccount) {
        this.operatorAccount = operatorAccount;
    }

    public String getOperatorName() {
        return operatorName;
    }

    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUa() {
        return ua;
    }

    public void setUa(String ua) {
        this.ua = ua;
    }

    public void setOperator(ISimpleUser su) {
        if (su != null) {
            if (su instanceof SessionBUser) {
                SessionBUser bsu = (SessionBUser) su;
                this.operatorId = bsu.getSid().getId();
                if (LoginMode.Proxy.getCode().equals(bsu.getLoginMode()) && bsu.getSrcUser() != null) {
                    this.operatorAccount = bsu.getSrcUser().getLoginName() + " 代 " + su.getLoginName();
                } else {
                    this.operatorAccount = su.getLoginName();
                }
                this.operatorName = bsu.getSid().getName();
                if (bsu.getCompany() != null) {
                    this.orgId = bsu.getCompany().getId();// .orgId();
                }
                this.orgType = bsu.getUserType();
            } else if (su instanceof SessionCUser) {
                SessionCUser cu = (SessionCUser) su;
                this.operatorId = cu.getSid().getId();
                this.operatorAccount = su.getLoginName();
                this.operatorName = cu.getSid().getName();
            }
        }
    }
}
